﻿/*
 * patient的相关业务
 * */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WH.NurseSys.Model;
using WH.NurseSys.BLL;

namespace WH.NurseSys.Web.Controllers
{
    public class PatientController : Controller
    {        
        //病人列表
        public ActionResult List()
        {
            List<Patient> patientList = new PatientBLL().GetList();
            return View(patientList);
        }

        //插入一个新的病人，展示页
        [HttpGet]
        public ActionResult Insert()
        {
            List<Dept> deptList=new DeptBLL().GetList();         
            return View(deptList);
        }

        //插入一个新的病人
        [HttpPost]
        public ActionResult Insert(string id)
        {
            string name = Request.Form["name"];
            string ageStr=Request.Form["age"];
            int age;
            if(string.IsNullOrWhiteSpace(ageStr))
                age=0;
            else
                int.TryParse(ageStr,out age);
            string deptIdStr=Request.Form["dept_id"];
            string genderStr = Request.Form["gender"];
            Patient patient = new Patient();
            patient.Id = Guid.NewGuid();
            patient.Name = name;
            patient.Age = age;
            patient.AgeUnit = "Y";
            patient.BedNo = Request.Form["bed_no"];
            patient.Birthdate = DateTime.Now;
            patient.ClinicDiag = Request.Form["clinic_diag"];
            patient.DeptId = Guid.Parse(deptIdStr);
            patient.Doctor = Request.Form["doctor"];
            patient.Gender = genderStr=="1"?true:false;
            patient.InDate = DateTime.Now;
            patient.InHosp = true;
            patient.InpatientNo = Request.Form["inpatient_no"];
            patient.OutDate = DateTime.Now.AddDays(10);          
            new PatientBLL().Insert(patient);
            return Redirect("/Patient/List/");
        }

    }
}
